package util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.concurrent.CountDownLatch;

public class KafkaSender {

    /**
     * 设计原则：本工具应该像坟墓一般简洁
     * 文件路径
     * 集群地址
     * topic名称
     * 线程数
     * 动态读取的kafka的配置文件地址，配置更改的生效方式
     *
     * 影响因素：文件大小、读取方式、线程数、kafka接收的确认机制、kafka集群的大小
     * 评价指标：不能丢数据，时间尽可能短
     *
     * 控制变量：文件大小：700m，读取方式BufferedReader，线程数3，kafka接收的确认机制1，集群大小3
     */
    private static final Logger logger = LoggerFactory.getLogger(KafkaSender.class);

    public static void main(String[] args) throws IOException {

        // 日志工具类

        String filePath = "MIS_CUSTLABEL_B00750_20241129.txt";

        BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(filePath)));

        long startTime = System.currentTimeMillis();

        long totalLines = bufferedReader.lines().count();
        System.out.println(totalLines);

        int threadNums = 9;

        long perThreadLines = (long) Math.ceil((totalLines + threadNums - 1)/threadNums);

        CountDownLatch countDownLatch = new CountDownLatch(threadNums);

        for (int i = 0; i < threadNums; i++) {
            long startLine = i * perThreadLines;
            long endLine = Math.min(startLine + perThreadLines, totalLines);
            System.out.println(startLine + "------" + endLine);
//            new Thread(new LineReaderTask(filePath, startLine ,endLine, countDownLatch)).start();
            sendMethod(startLine, endLine);
        }

        String line = "";

        long endTime = System.currentTimeMillis();

//        logger.info("开始时间是：" + startTime + ", 结束时间是：" + endTime + ", 总计花费时间是：" + (endTime - startTime) +
//                "ms -" + threadNums + "线程System.out读输出读730m的文件");


    }

    private static void sendMethod(long startLine, long endLine) {
        long currentLine = 0;

        while(currentLine <= endLine){
//                System.out.println(line);
            if(currentLine > startLine || currentLine == 0){
                System.out.println("发送" + currentLine);
            }
            currentLine ++;
        }
    }


}
